#include <vector>
#include "../checkers/PiecePosition.h"

using namespace std;

class Path
{
public:
	Path():isJumpPath(false),priority(0){}
	Path(Path* copyPath): priority(0)
	{
		(*this) = (*copyPath);
	}

	virtual ~Path()
	{
		for( size_t i = 0; i < path.size(); i++)
		{
			PiecePosition* md = dynamic_cast<PiecePosition*>(path[i]);
			if( md != 0 )
			{
				delete md;
			}
		}

		path.clear();
	}

    Path &operator=(Path &obj)
	{
		SetPieceAndPosition(obj.GetPosition().GetX(), 
							obj.GetPosition().GetY(),
							obj.GetPiece());

		SetJumpStatus(obj.GetJumpStatus());

		for( size_t i = 0; i < obj.GetPath().size(); i++)
		{
			PiecePosition* md = dynamic_cast<PiecePosition*>(obj.GetPath()[i]);
			AddPathPoint(md->GetX(), md->GetY());
		}

		return *this;
	}


	int GetPriority() 
	{
		// Priority is based on number of moves and an additional 1 is added
		// if a move is a capture.
		return (int)path.size() + (isJumpPath?1:0);
	}
	
	int GetPiece() { return pieceType;}
	
	vector<PiecePosition*> GetPath() { return path;}

	PiecePosition& GetPosition(){ return position;}

	void SetPieceAndPosition(int x, int y, int piece) 
	{
		pieceType = piece;
		position.Set(x,y);
	}

	void AddPathPoint(int x, int y)
	{
		PiecePosition* pos = new PiecePosition(x,y);
		path.push_back(pos);
	}


	void SetJumpStatus(bool status) { isJumpPath = status;}

	bool GetJumpStatus() { return isJumpPath;}

private:
	int pieceType;
	bool isJumpPath;
	PiecePosition position;
	int priority;
	vector<PiecePosition*> path;
};
